//note: predicate 断言,返回true 后，就是断言类型
function isString(test: any): test is string{
  return typeof test === "string";
}
//
function example(foo: any){
  if(isString(foo)){
    console.log("it is a string" + foo);
    console.log(foo.length); // string function
  }
}
example("hello world");


//note: 非空断言
const a: number | undefined = undefined;
const b: number = a!;
console.log(b);

namespace testD{
  let x!: number;
  initialize();
// Variable 'x' is used before being assigned.(2454)
  console.log(2 * x); // Error

  function initialize() {
    x = 10;
  }
}
